package com.gitee.wsl.doc.prosemirror.model.dom.parser.rule

import com.gitee.wsl.doc.prosemirror.model.attr.Attrs
import com.gitee.wsl.doc.prosemirror.model.mark.Mark
import com.gitee.wsl.doc.prosemirror.model.dom.parser.ParseRuleMatch

// A parse rule targeting a style property.
interface StyleParseRule : ParseRule {
    // A CSS property name to match. This rule will match inline styles
    // that list that property. May also have the form
    // `"property=value"`, in which case the rule only matches if the
    // property's value exactly matches the given value. (For more
    // complicated filters, use [`getAttrs`](#model.ParseRule.getAttrs)
    // and return false to indicate that the match failed.) Rules
    // matching styles may only produce [marks](#model.ParseRule.mark),
    // not nodes.
    val style: String

    // Given to make TS see ParseRule as a tagged union @hide
//    val tag: Any?

    // Style rules can remove marks from the set of active marks.
    val clearMark: ((mark: Mark) -> Boolean)?

    // A function used to compute the attributes for the node or mark
    // created by this rule. Called with the style's value.
    val getStyleAttrs: ((style: String) -> ParseRuleMatch)?
}

data class StyleParseRuleImpl(
//    override val tag: String? = null,
    override val style: String,
    override val priority: Int? = null,
    override val consuming: Boolean? = null,
    override val context: String? = null,
    override var mark: String? = null,
    override var clearMark: ((mark: Mark) -> Boolean)? = null,
    override val ignore: Boolean? = null,
    override val closeParent: Boolean? = null,
    override val skip: Boolean? = null,
    override var attrs: Attrs? = null,
    override val getStyleAttrs: ((style: String) -> ParseRuleMatch)? = null,
) : StyleParseRule, ParseRule {
    override fun copyRule() = this.copy()
}

fun isStyleRule(rule: ParseRule) = (rule as? StyleParseRule)?.style != null